package io.kiki.sba.registry.client.task;

import io.kiki.sba.registry.client.remoting.Client;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter

public abstract class AbstractWorkerThread extends Thread implements Worker {

    private final Object object = new Object();


    protected Client client;


    public AbstractWorkerThread(Client client) {
        this.client = client;
    }

    /**
     * Await for next task.
     */
    void await(long timeout) throws InterruptedException {
        synchronized (object) {
            object.wait(timeout);
        }
    }

    /**
     * Notify execute signal for task thread.
     */
    void signal() {
        synchronized (object) {
            object.notifyAll();
        }
    }


    @Override
    public void run() {
        handle();
    }
}
